package com.woniuxy.controller;

import com.woniuxy.entity.DrugItem;
import com.woniuxy.entity.InspectItem;
import com.woniuxy.entity.PageBean;
import com.woniuxy.entity.ResponseResult;
import com.woniuxy.service.DrugItemService;
import com.woniuxy.service.InspectItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class InspectItemController {
    @Autowired
    InspectItemService inspectItemService;
    /*
    * 删除检查条目
    * */
    @DeleteMapping("/inspectItem/{inspectItemId}")
    public ResponseResult removeInspectItem(@PathVariable int inspectItemId){
        InspectItem inspectItem=new InspectItem();
        inspectItem.setInspectItemId(inspectItemId);
        inspectItemService.deleteInspectItems(inspectItem);
        return new ResponseResult(200,"success",null);
    }
    /*
     * 添加药品条目
     * */
    @PostMapping("/addInspectItem")
    public ResponseResult test(@RequestBody InspectItem inspectItem ){
        String s = inspectItemService.addInspectItems(inspectItem);
        if("存在".equals(s)){
            return new ResponseResult(200,"exist",null);
        }
        return new ResponseResult(200,"success",null);
    }

    /*
     * 按处方id查询药品处方
     * */
    @GetMapping("/getInspectItems/{pageIndex}/{pageSize}/{prescriptionNo}")
    public ResponseResult getInspectItems(
            @PathVariable String prescriptionNo,
            @PathVariable int  pageIndex,
            @PathVariable int pageSize ){
        log.debug("进入getInspectItems");
        PageBean<InspectItem> pageBean = inspectItemService.getAllInspectItemByPrescriptionNo(prescriptionNo, pageIndex, pageSize);
        return new ResponseResult(200,"success",pageBean);
    }
    @PutMapping("/modifyInspectItemResult")
    public ResponseResult modifyInspectItemResult(@RequestBody InspectItem inspectItem){
        inspectItemService.modifyInspectItemResult(inspectItem);
        return new ResponseResult(200,"success",null);
    }
}
